package com.bingo.demo.service;

import com.bingo.demo.DAO.CommentMapper;
import com.bingo.demo.pojo.Comment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

@Service
public class CommentService {

    @Autowired
    CommentMapper commentMapper;

    public void addComment(Comment comment){
        Date date = new Date();
        Timestamp ts=new Timestamp(date.getTime());
        comment.setPublishTime(ts);
        commentMapper.addComment(comment);
    }

    public List<Comment> findByEssayId(Integer essayId){
        List<Comment> list = commentMapper.findByEssayId(essayId);
        return list;
    }

    public Comment findById(Integer id){
        Comment comment = commentMapper.findById(id);
        return comment;
    }

    public void deleteById(Integer id){
        commentMapper.deleteById(id);
    }
}
